﻿using System;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Game.Contract;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 获得玩家头像
	/// </summary>
	public class Action10017 : BaseAction
	{
		private int _userId;
		private bool _result = false;
		private string _log = "查询有误";
		private string _headIcon = string.Empty;

		public Action10017(HttpGet actionGetter)
			: base((short)ActionType.DZGetUserHeadIcon, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("UserID", ref _userId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			try
			{
				_headIcon = GameTable.Current.GetUserHeadIconByUserId(_userId);
				if(!string.IsNullOrEmpty(_headIcon))
				{
					_result = true;
					_log = "查询正确";
				}
				return true;
			}
			catch (Exception ex)
			{
				Tool.WriteErrorLine("10017消息异常:" + ex.ToString());
				return false;
			}
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(_result);
			this.PushIntoStack(_log);
			this.PushIntoStack(_userId);
			this.PushIntoStack(_headIcon);
		}
	}
}
